package com.acme;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.ClientRegistrationListener;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.domain.bank.SavingsAccount;
import com.acme.bankapp.service.bank.AccountDoesntExistsException;
import com.acme.bankapp.service.bank.BankService;
import com.acme.bankapp.service.bank.ClientExistsException;
import com.acme.bankapp.service.bank.NotEnoughFundsException;

public class BankApplication {
	static ClientRegistrationListener[] listeners = new ClientRegistrationListener[] {
			new Bank.PrintClientListener(),
			new Bank.EmailNotificationListener(), new Bank.DebugListener() };

	public static void main(String[] args) {

		BankService bankService = new BankService();
		Bank bank1 = new Bank(listeners);
		try {
			Client client1 = bankService.addClient(bank1, "Alex", Gender.MALE);
			Account account1 = new CheckingAccount(1, 10000.00, 100000.00);
			client1.addAccount(account1);

			Client client2 = bankService.addClient(bank1, "Bryan", Gender.MALE);
			Account account2 = new CheckingAccount(2, 1000000.00, 500000.00);
			client2.addAccount(account2);

			Client client3 = bankService.addClient(bank1, "Cristina",
					Gender.FEMALE);
			Account account3 = new SavingsAccount(3, 150000.00);
			client3.addAccount(account3);

			Client client4 = bankService.addClient(bank1, "Den", Gender.MALE);
			Account account4 = new SavingsAccount(4, 570000.00);
			client4.addAccount(account4);

			Client client5 = bankService.addClient(bank1, "Elly", Gender.MALE);
			Account account5 = new CheckingAccount(5, 10000.00, 70000.00);
			client5.addAccount(account5);

		} catch (ClientExistsException cl) {
			System.out.println(cl.getMessage());
		} catch (IllegalArgumentException IAExc) {
			System.out.println(IAExc.getMessage());
		}

		try {
			bankService.printBalance(bank1);
		} catch (AccountDoesntExistsException e) {
			System.out.println(e.getMessage());
		}

		try {
			bankService.printMaximumAmountToWithdraw(bank1);
		} catch (AccountDoesntExistsException e) {
			System.out.println(e.getMessage());
		}

		try {
			bankService.modifyBank(bank1);
		} catch (AccountDoesntExistsException e) {
			System.out.println(e.getMessage());
		} catch (NotEnoughFundsException fExc) {
			System.out.println(fExc.getMessage());
		}
		try {
			bankService.printBalance(bank1);
		} catch (AccountDoesntExistsException e) {
			System.out.println(e.getMessage());
		}

	}
}
